using System;
using System.Collections.Generic;
using System.Drawing;
using System.Web.UI.WebControls;
using HRM.BLL;
using HRM.DAL.DAO;

namespace HRM.UI.HRManagerUI.Profile
{
    public partial class ReadApplication : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadApplication();
            }
        }

        private void LoadApplication()
        {
            ApplicationManager manager = new ApplicationManager();
            List<LeaveApplication> applications = new List<LeaveApplication>();
            applications = manager.GetAllApplication();
            applicationGdv.DataSource = applications;
            applicationGdv.DataBind();

            int unread = manager.CountUnReadApplication();
            unreadLbl.Text = unread.ToString();
            lblTtotalApp.Text = applications.Count.ToString();
        }

        protected void applicationGdv_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            try
            {
                ApplicationManager manager = new ApplicationManager();

            }
            catch (Exception)
            {

                throw;
            }
        }

        protected void applicationGdv_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            applicationGdv.PageIndex = e.NewPageIndex;
            LoadApplication();
        }

        protected void DeleteApplication(object o, EventArgs e)
        {
            foreach (GridViewRow gvr in applicationGdv.Rows)
            {
                CheckBox chkBox = (CheckBox)gvr.FindControl("check");
                if (chkBox != null && chkBox.Checked)
                {
                    int id = Convert.ToInt32(((Label)gvr.FindControl("appId")).Text);
                    ApplicationManager manager = new ApplicationManager();
                    if (manager.DeleteApplication(id))
                    {
                        msgLbl.ForeColor = Color.Green;
                        msgLbl.Text = "Application Deleted Successfully";
                        LoadApplication();
                    }
                }
            }
        }
    }
}